﻿using Microsoft.EntityFrameworkCore;
using ServiceStack.Script;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZH.Infrastructure.Attr;
using ZH.Infrastructure.Dto.Response;
using ZH.Infrastructure.IOC;
using ZH.Service.Interface;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;

namespace ZH.Service.Instance
{
    [Inject_]
    public class Reservation_Service : Base_Service, I_Reservation_Service
    {
        private readonly Reservation_IOC _reservation_IOC;

        public Reservation_Service(Reservation_IOC reservation_IOC)
        {
            _reservation_IOC = reservation_IOC;
        }

        public async Task<Api_Response_Dto> Get_reservationList(int? page, int? limit, string? key, string? time)
        {
            var data = await _reservation_IOC._reservation_EFCore.QueryAll(out int total,
                  Convert.ToInt32(page), Convert.ToInt32(limit),
                  true,
                  o => o.Aid,
                    d => (string.IsNullOrEmpty(key) || d.CustomerName.Contains(key))&&(string.IsNullOrEmpty(time)||(d.AppointmentDate.Substring(0, 9) == time || d.AppointmentDate.Substring(0, 10) == time))
                  ).ToListAsync();



            return Result(1, "ok", new
            {
                total,
                data
            });
        }

        public async Task<Api_Response_Dto> Get_today(int? page, int? limit, string? key)
        {

            //获取当天的起始和结束时间
         string  todayStart = DateTime.Now.ToString("yyyy-M-dd");

            // 查询当天的订单并分页
            var data = await _reservation_IOC._reservation_EFCore.QueryAll(
                out int total,
                Convert.ToInt32(page),
                Convert.ToInt32(limit),
                true,
            o => o.Aid// 排序字段
                      , d => d.AppointmentDate.Substring(0, 9) == todayStart || d.AppointmentDate.Substring(0, 10) == todayStart// 筛选条件：当天的订单
            ).ToListAsync();
            return Result(1, "ok", new
            {
                total,
                data
            });
        }
    }
}
